desc "Runs all the tests"
lane :test do
  Dir.chdir("..") do
    sh("xcodebuild test -project FontAwesome.xcodeproj -scheme FontAwesome -destination 'platform=iOS Simulator,name=iPhone 11 Pro Max' | xcbeautify")
    sh("xcodebuild -project FontAwesome.xcodeproj -scheme FontAwesome-watchOS -destination 'OS=5.1,name=Apple Watch Series 4 - 44mm' | xcbeautify")
  end
end

desc "Update to new version of Font Awesome"
lane :update_font do |options|
  target_version = options[:version]
  raise "The version is missed. Use `bundle exec fastlane bum_web_font version:{version_number}`.`" if target_version.nil?

  sh("cd #{ENV["PWD"]}/FortAwesome/Font-Awesome && git fetch origin && git checkout #{target_version}")
  sh("/bin/cp -f #{ENV["PWD"]}/FortAwesome/Font-Awesome/otfs/*.otf #{ENV["PWD"]}/FontAwesome")
  sh("cd #{ENV["PWD"]} && swift run tools")
  sh("git commit -m \"Update font version to #{target_version}\" ../FontAwesome ../FortAwesome")
end

desc "Release a new version"
lane :release do |options|
  target_version = options[:version]
  raise "The version is missed. Use `bundle exec fastlane release version:{version_number}`.`" if target_version.nil?

  ensure_git_branch
  ensure_git_status_clean

  test
  pod_lib_lint(
    allow_warnings: true,
  )

  increment_version_number(version_number: target_version)
  version_bump_podspec(path: "FontAwesome.swift.podspec", version_number: target_version)

  git_commit(path: ".", message: "Bump version to #{target_version}")
  add_git_tag(tag: target_version, message: target_version)
  push_to_git_remote

  pod_push(
    allow_warnings: true,
    use_bundle_exec: true,
  )
end
